package com.pruebas.andEngine;

import org.anddev.andengine.engine.handler.physics.PhysicsHandler;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.opengl.vertex.RectangleVertexBuffer;

public class PowerUp extends AnimatedSprite{
	private final PhysicsHandler mPhysicsHandler;
	private Boolean isGoingUp = true;
	static final int DESPLAZAMIENTOX = 10;
	static final int DESPLAZAMIENTOY = 10;
	private int camara_width = 0;
	private int camera_height = 0;
	private Boolean isColisioned = false;

	public PowerUp(float pX, float pY, TiledTextureRegion pTiledTextureRegion) {
		super(pX, pY, pTiledTextureRegion);
		this.mPhysicsHandler = new PhysicsHandler(this);
	    this.registerUpdateHandler(this.mPhysicsHandler);
	}
	
	public boolean moveSprite(int valor){
		if(!isColisioned){
			if(isGoingUp){
				this.setPosition(this.getX() - (DESPLAZAMIENTOX + valor), this.getY() - (DESPLAZAMIENTOY + valor));
				if( this.getY() <= camera_height / 2)
					isGoingUp = false;
			}
			else{
				if(this.getY() >= camera_height -115)
					isGoingUp = true;
				else
					this.setPosition(this.getX() - (DESPLAZAMIENTOX + valor), this.getY() + (DESPLAZAMIENTOY + valor));
			}
			
			//fin pantalla
			if(this.getX() <= -this.getWidth()){
				this.stopAnimation();
				return false;
			}
			return true;
		}
		else{
			this.setVisible(false);
			this.stopAnimation();
			this.reset();
			isColisioned = false;
			return false;
		}
	}

	public Boolean getIsGoingUp() {
		return isGoingUp;
	}

	public void setIsGoingUp(Boolean isGoingUp) {
		this.isGoingUp = isGoingUp;
	}

	public int getCamara_width() {
		return camara_width;
	}

	public void setCamara_width(int camara_width) {
		this.camara_width = camara_width;
	}

	public int getCamera_height() {
		return camera_height;
	}

	public void setCamera_height(int camera_height) {
		this.camera_height = camera_height;
	}

	public Boolean getIsColisioned() {
    	return isColisioned;
    }

	public void setIsColisioned(Boolean isColisioned) {
    	this.isColisioned = isColisioned;
    }
}
